using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection; 
using NUnit.Framework;
using HermesPortal.Core; 
namespace HermesPortal.NUnit
{
    [TestFixture] 
    public class SagaServicesFixture
    {
        private const int TESTCOVENANTID = 1;
        private const int TESTCREATORID = 1;
        [Test]
        public void GetSaga()
        {
           Saga saga = SagaServices.GetSaga(TESTCOVENANTID);
           Assert.IsNotNull(saga);

           ViewBusinessObjectProperties(saga);
       }
        [Test]
        public void GetSagas()
        {
            // test to get all sagas 
            List<Saga> sagas = null;
            sagas = SagaServices.GetSagas();
            Assert.IsTrue(sagas.Count <= 0,"No Sagas where returned." );
            foreach (Saga saga in sagas)
            {
                ViewBusinessObjectProperties(saga);
            }
 
        }

        // Test to get Saga info for a creator
        [Test]
        public void GetSagasWithCreatorID()
        {

            List<Saga> sagas = null;
            sagas = SagaServices.GetSagasByCreator(TESTCREATORID);
            Assert.IsTrue(sagas.Count > 0, "No Sagas where returned.");
            foreach (Saga saga in sagas)
            {
                ViewBusinessObjectProperties(saga);
            }
        }

       #region Helper methods
       private void ViewBusinessObjectProperties(object obj)
        {
           Type objType = obj.GetType();
           PropertyInfo [] props  = objType.GetProperties();
           foreach (PropertyInfo prop in props)
          { 
              FieldInfo fi = objType.GetField(prop.Name);
               Console.WriteLine(prop.Name+ ": " + prop.GetValue(obj,null));   
          }
      }
       #endregion
  }
}
